package com.dalonedrau.jogl.engine;

import java.applet.Applet;

import com.ahq.main.AHQApplet;

/**
 * Applet entry point.
 * @author Donald
 */
public abstract class GameApplet extends Applet {
	/** the one and only instance of the <code>GameApplet</code> class. */
	private static GameApplet	instance;
	protected static void setInstance(final GameApplet applet) {
		GameApplet.instance = applet;
	}
	/** serial id. */
	private static final long	serialVersionUID	= 1L;
	/**
	 * Gives access to the singleton instance of {@link GameApplet}.
	 * @return {@link GameApplet}
	 */
	@SuppressWarnings("serial")
	public static GameApplet getInstance() {
		if (GameApplet.instance == null) {
			GameApplet.instance = new GameApplet() {};
		}
		return GameApplet.instance;
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public final void destroy() {
		Engine.getEngine().stop();
	}
	/** <code>LogItem</code> object. */
	// private static final Log LOGGER = LogFactory.getLog(AresApplet.class);
	/**
	 * Processes a fatal error and stops the game.
	 * @param ex the error
	 */
	public final void fatalError(final Exception ex) {
		ex.printStackTrace();
		Engine.getEngine().stop();
		this.exit();
	}
	public void exit() {
		GameApplet.instance.stop();
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public final void stop() {
		Engine.getEngine().stop();
	}
}
